const Response = require("../../class/Response");

WSS.onEvent("PlayerMessage", async (thisClient, req, res)=>{
    let sender = req.json.body.sender;
    let sendmsg = req.json.body.message;

    // 查询在线
    if (sendmsg == ".online"){
        thisClient.sendText(`${CONSTANTS.TIP_HEADER} §e当前在线: §r${WSS.clientsManager.length}个连接`);
        thisClient.sendText(`${CONSTANTS.TIP_HEADER} ${WSS.clientsManager.getOnlineClientsName()}`);
        return false;
    }

    // loc定位命令
    if (sendmsg == "./loc"){
        thisClient.sendJson(
            new Response(Response.MODE.CMD)
            .setCmd("testforblock ~~~ air")
            .setMetaData({purpose: "/vanilla/cmd/locatePos"})
            .setData({sender: sender}),
            (req, res)=>{
                if (req.json.body.statusCode != 0){
                    thisClient.sendText(`${CONSTANTS.TIP_HEADER} §c定位生成点失败`);
                    return false;
                }
                thisClient.locPos = req.json.body.position;
                thisClient.sendText(`${CONSTANTS.TIP_HEADER} §a定位生成原点: §r${thisClient.locPos.x}, ${thisClient.locPos.y}, ${thisClient.locPos.z}`);
                return false;
            }
        );
        return false;
    }

    // help命令
    if (sendmsg == "./help"){
        //thisClient.sendText(HelpInfo);
        return false;
    }
});